<template>
	<view class="content">
		<template v-if="list.length>0">
			<view class="shop-block" v-for="(item,index) in list" :key="item.id">
				<view class="shop-left">
					<image :src="cloudStorage+item.businessFace" mode="widthFix"></image>
				</view>
				<view class="shop-right">
					<view class="shop-title">
						{{item.name}}
					</view>
					<view class="shop-tips">
						<!-- <image src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/renqi.png"></image> -->
						<view class="tips">
							{{item.label}}名
						</view>
					</view>
					<view class="shop-address">
						<view class="address-left">
							<image
								src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/site.png">
							</image>
							<view class="address">
								{{item.address}}
							</view>
						</view>
						<view class="address-right">
							<image
								src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/distance.png">
							</image>
							<view class="distance">
								{{item.distance}}km
							</view>
						</view>
					</view>
					<view class="shop-btn"
						@click="navigate('/page_other/start_bus/detail?id='+item.id+'&latitude='+latitude+'&longitude='+longitude)">
						我要报名
					</view>
				</view>
			</view>
		</template>
		<view v-if="more==false&&list.length==0" style="width:100%;text-align: center;">暂无数据</view>
		<view v-else-if="more==false&&list.length>0" style="width:100%;text-align: center;">没有更多了</view>
	</view>
</template>

<script>
	import {
		getUserEntrepreneursList
	} from '@/api/bus.js'
	import {
		isMore
	} from '@/util/util.js'
	export default {
		data() {
			return {
				latitude: '',
				longitude: '',
				conf: {
					page: 1,
					limit: 10,
				},
				more: true,
				list: [],
			}
		},
		methods: {
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			//列表
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				uni.getLocation({
					success: (current) => {
						this.latitude = current.latitude;
						this.longitude = current.longitude;
						uni.setStorageSync('latitude', this.latitude)
						uni.setStorageSync('longitude', this.longitude)
						getUserEntrepreneursList({
							page: this.conf.page,
							limit: this.conf.limit,
							latitude: this.latitude,
							longitude: this.longitude,
						}).then((res) => {
							let list = res.list || [];
							if (refresh) {
								this.list = list;
							} else {
								this.list = [...this.list, ...list]
							}
							this.more = isMore(this.conf.page, this.conf.limit, res.count)
						})
					}
				})
			},
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList();
			}
		},
		onLoad() {
			this.getList(true);
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		padding: 20rpx 30rpx 0;

		.shop-block {
			margin-top: 20rpx;
			display: flex;
			width: 100%;
			background-color: #FFFFFF;
			padding: 30rpx;
			border-radius: 20rpx;

			.shop-left {
				width: 220rpx;
				border-radius: 20rpx;
				margin-right: 20rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 20rpx;
				}
			}

			.shop-right {
				width: calc(100% - 220rpx);

				.shop-title {
					font-size: 32rpx;
					color: #1A1A1A;
					font-weight: bold;
				}

				.shop-tips {
					margin-top: 12rpx;
					width: 100%;
					display: flex;
					align-items: center;
					border-radius: 10rpx;
					text-align: center;

					image {
						width: 20rpx;
						height: 20rpx;
						margin-right: 10rpx;
					}

					.tips {
						font-size: 24rpx;
						color: #FF6831;
						background-color: #FEF3EF;
						font-weight: normal;
						padding: 5rpx 10rpx;
					}
				}

				.shop-address {
					width: 100%;
					display: flex;
					justify-content: space-between;
					margin-top: 12rpx;

					.address-left {
						// width: calc(100% -70rpx);
						display: flex;
						justify-content: center;
						align-items: center;

						image {
							width: 20rpx;
							height: 20rpx;
							margin-right: 8rpx;
						}

						.address {
							width: 230rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							font-size: 24rpx;
							color: #767676;
						}
					}

					.address-right {
						display: flex;
						justify-content: center;
						align-items: center;

						image {
							width: 20rpx;
							height: 20rpx;
							margin-right: 4rpx;
						}

						.distance {
							font-size: 24rpx;
							color: #767676;
						}
					}
				}

				.shop-btn {
					width: 50%;
					padding: 5rpx 34rpx;
					background: linear-gradient(90deg, #FF2F34 0%, #FF6B18 100%);
					border-radius: 100rpx;
					text-align: center;
					color: #FFFFFF;
					margin-top: 12rpx;
				}
			}

		}
	}
</style>